﻿using Senparc.Weixin.MP.Containers;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Configuration;
using System.Web.Mvc;
using System.Web.Routing;
using Senparc.CO2NET;
using Senparc.Weixin;
using Senparc.CO2NET.RegisterServices;
using Senparc.Weixin.Entities;

namespace wxkq
{
    public class MvcApplication : System.Web.HttpApplication
    {
        protected void Application_Start()
        {
            AreaRegistration.RegisterAllAreas();
            RouteConfig.RegisterRoutes(RouteTable.Routes);
            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);

            string AppId = WebConfigurationManager.AppSettings["WxOpenAppId"];//与微信小程序账号后台的AppId设置保持一致，区分大小写。
            string AppSecret = WebConfigurationManager.AppSettings["WxOpenAppSecret"];//与微信小程序账号后台的AppId设置保

            var isGLobalDebug = true;//设置全局 Debug 状态
            var senparcSetting = SenparcSetting.BuildFromWebConfig(isGLobalDebug);
            var register = RegisterService.Start(senparcSetting).UseSenparcGlobal();//CO2NET全局注册，必须！

            var isWeixinDebug = true;//设置微信 Debug 状态
            var senparcWeixinSetting = SenparcWeixinSetting.BuildFromWebConfig(isWeixinDebug);
            register.UseSenparcWeixin(senparcWeixinSetting, senparcSetting);////微信全局注册，必须！

            try
            {
                RegisterService.Start(senparcSetting).UseSenparcWeixin(senparcWeixinSetting, senparcSetting);
                // register.UseSenparcWeixin(senparcWeixinSetting, senparcSetting);////微信全局注册，必须！

                Senparc.Weixin.WeixinTrace.SendCustomLog("系统日志", "微信全局");
                Senparc.CO2NET.Trace.SenparcTrace.SendCustomLog("系统日志", "微信全局");
                //register.RegisterThreads();
            }
            catch (Exception ex)
            {
                Senparc.CO2NET.Trace.SenparcTrace.SendCustomLog("系统日志", ex.Message);
            }

            AccessTokenContainer.Register(AppId, AppSecret);
        }
    }
}
